<template>
  <div>
    <loading2 v-if="!list.length">loading.......</loading2>
    <div v-if="list.length">
      <div 
      class="item" 
      v-for="(item, index) in list2" 
      :key="index"
      @click="godetail(item)"
      >
        <div class="left">
            <!-- :src  v-lazy -->
          <img v-lazy="item.poster" alt="" />
        </div>
        <div class="middle">
          <div>{{ item.name }}</div>
          <div v-if="type === 1">
            <span>观众评分</span>
            <span class="grade">{{
              item.grade ? item.grade : "暂无数据"
            }}</span>
          </div>

          <div>主演:{{ item.actors | parseActors }}</div>
          <div>{{ item.nation }} | {{ item.runtime }}分钟</div>
        </div>

        <div class="right">
          <span v-if="type === 1">购票</span>
          <span v-else>预售</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import loading1 from "@/components/loading1";
import loading2 from "@/components/loading2";
export default {
  props: ["list", "type"],
  components: { loading1, loading2 },
  data() {
    return {
      flag1: true,
      list2: "",
    };
  },

  methods: {
      godetail(item){
          console.log('来到了godetal里面了')
          console.log('item',item)
          this.$router.push('/filmdetail/' + item.filmId)
      }
  },

  computed: {
    //   这是第四种切换loading的方式
    isflagcompu() {
      console.log("进入computed isflagcompu");
      return this.list[0];
    },
  },

  watch: {
    list(newval) {
      console.log("来到了film list watch里面了");
      console.log("list", this.list);
      // 第二种切换  loading的做法 无bug
      this.flag1 = false;
      this.list2 = this.list;
    },
  },

  filters: {
    parseActors: function (value) {
      let actors = "";
    //   console.log("进入 parseActors 过滤器了  ", value);
      if (value) {
        value.forEach((element) => {
          actors += element.name + "  ";
        });
      }else {
          actors ='暂无'
      }


      return actors 
    },
  },

  beforeCreate() {
    console.log(" film list beforeCreate");
  },

  created() {
    //   第一种课件做法
    console.log(" film list  created");
    //   这是第一种  切换loading的方式
    // if (this.list.length > 0) {
    //   this.flag1 = false;
    // }
  },

  beforeMount() {
    console.log(" film list beforeMount");
  },

  mounted() {
    console.log(" film list mounted");
  },

  beforeUpdate() {},

  updated() {},

  beforeDestroy() {},

  destroyed() {},
};
</script>


<style  lang='scss'>
.item {
  margin-top: 15px;
  padding-bottom: 35px;
  display: flex;
  color: #797d82;
  font-size: 13px;
  border-bottom: 1px solid #ededed;

  .left {
    width: 77px;
    height: 100px;
    margin-left: 20px;
    img {
      width: 66px;
      height: 100%;
    }
  }

  .middle {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 55%;

    div:nth-of-type(1) {
      color: #191a1b;
      font-size: 16px;
    }

    div:nth-of-type(3) {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .right {
    width: 15%;
    display: flex;
    align-items: center;
    margin-right: 20px;

    span {
      border: 1px solid #ff5f16;
      background: white;
      color: #ff5f16;
      border-radius: 2px;
      height: 25px;
      line-height: 25px;
      font-size: 13px;
      width: 50px;
      text-align: center;
    }
  }
}

.pingfen {
  color: red;
}
.comfilmlistdivall {
  margin-bottom: 80px;
}
</style>
